package com.smarthospital.web.controller;

import com.smarthospital.common.Result.ResultDTO;
import com.smarthospital.entity.dto.TrtcUserSigDTO;
import com.smarthospital.service.IMControlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * create by sym  2020/8/16 16:00.
 */
@RestController
@Slf4j
@RequestMapping("/imc")
@Api(tags = "音视频辅助控制接口")
public class IMController {

    @Autowired
    private IMControlService imControlService;


    @GetMapping("/startIM")
    @ApiOperation(value = "开始聊天\n" +
            "param type -> 0_音频 1_视频\n" +
            "orderId 订单id")
    public ResultDTO startIM(@RequestParam("type")Integer type,@RequestParam("orderId")String orderId,@RequestHeader("SH_TOKEN")String SH_TOKEN)  {
        imControlService.startIM(type,orderId);
        return ResultDTO.sucess();
    }

    @GetMapping("/closeIM")
    @ApiOperation(value = "结束聊天\n" +
            "param type -> 0_音频 1_视频\n" +
            "orderId 订单id")
    public ResultDTO closeIM(@RequestParam("type")Integer type, @RequestParam("orderId")String orderId, @RequestHeader("SH_TOKEN")String SH_TOKEN)  {
        imControlService.closeIM(type,orderId);
        return ResultDTO.sucess();
    }

    @GetMapping("/checkIM")
    @ApiOperation(value = "检测是否可以发起聊天\n" +
            "param type -> 0_音频 1_视频\n" +
            "orderId 订单id")
    public ResultDTO checkIM(@RequestParam("type")Integer type,@RequestParam("orderId")String orderId,@RequestHeader("SH_TOKEN")String SH_TOKEN)  {
        imControlService.checkIM(type,orderId);
        return ResultDTO.sucess();
    }

    @GetMapping("/initRoom")
    @ApiOperation(value = "初始化聊天\n" +
            "orderId 订单id")
    public ResultDTO initRoom(@RequestParam("orderId")String orderId,@RequestHeader("SH_TOKEN")String SH_TOKEN)  {
        TrtcUserSigDTO trtcUserSig = imControlService.initRoom(orderId);
        return ResultDTO.sucess(trtcUserSig);
    }


}
